$(function() {
	$(".install_place_div").click(function() {
		var ckb_id = $(this).attr("type");
		var st = $("#"+ckb_id).attr("checked");
		$("#"+ckb_id).attr("checked", !st);
	});
});

function install() {
	var installPlaces = getCheckboxValues("install_place_checkbox");
	if(empty(installPlaces)) {
		alert("您尚未选择安装位置！！！");
		return;
	}
	
	var params = getChooseStyle();
    var itemStr = buildItemJsonStr();
	if(itemStr===''){
		$('#submit_feedback_div').html("<div class='red fb f22'>请在第1步选择您要推广的宝贝</div>")
		$('#submit_feedback_div').show();
	    return;
	}
	params["itemsStr"] = itemStr;
	params["promot"] = $("input[name='promot']:checked").val();
	params["installPlaces"] = installPlaces;
	switch(params["promot"]) {
		case "custom" : 
			params["installItemIids"] = buildItemIidStr("piids_promot");break;
		case "someCategory" : 
			params["cats"] = getCheckboxValues("seller_cats_promote");
			break;
		case "itemCategory" : 
			params["cats"] = getCheckboxValues("item_cats_promote");
			break;
		case "all" : case "onSale" : default : 
			break;
	}
	var wait_html = "<div style='margin-left: 80px; font-size: 12px; display: none;' id='waiting'>";
	wait_html += "<img style='margin-left: 250px;' src='/img/waiting.gif'>";
	wait_html += "<br>根据您安装代码的宝贝数量及网络情况，这可能需要1-15分钟，请耐心等待，不要关闭页面。</div>";
	$('#submit_feedback_div').html(wait_html);
	$('#submit_feedback_div').show();

	$.post("install.action",  params,
    	function(data,status) {
    		$('#submit_feedback_div').html(data.result);
    	}, 
    	"json"
    );
}

function validate_tab2() {
	var promot = $("input[name='promot']:checked").val();
	switch(promot) {
		case "custom" :
			var piids = buildItemIidStr("piids_promot");
			if(empty(piids)) {
				alert("您尚未选择安装宝贝！！！");
				return false;
			}
			return true;
		case "someCategory" : 
			var cats = getCheckboxValues("seller_cats_promote");
			if(empty(cats)) {
				alert("您的尚未选择安装类目！！！");
				return false;
			}
			return true;
		case "all" : case "onSale" : default :
			return true;
	}
}